Object.defineProperty(exports, "__esModule", {
    value: !0
});

var t = require("../../utils/config"), i = require("../../utils/request"), e = require("../../utils/api"), a = require("../../utils/storage"), n = require("../../utils/map-convert");

Component({
    properties: {
        marginTop: {
            type: String,
            value: "0px"
        },
        contentMagin: {
            type: String,
            value: "0px"
        }
    },
    data: {
        themeColor: getApp().globalData.themeColor,
        background: [],
        indicatorDots: !0,
        vertical: !1,
        autoplay: !1,
        interval: 2e3,
        duration: 500,
        screenWidth: 0,
        screenHeight: 0,
        imgwidth: 0,
        imgheight: 0,
        latitude: "",
        longitude: "",
        institution: {},
        showRecommendInstitution: !1,
        privacyContractName: "",
        showPrivacy: !1
    },
    lifetimes: {
        attached: function() {
            var t = this;
            wx.getPrivacySetting({
                success: function(i) {
                    i.needAuthorization ? t.setData({
                        privacyContractName: i.privacyContractName,
                        showPrivacy: !0
                    }) : (t.init(), t.getLoc());
                }
            });
        }
    },
    methods: {
        openPrivacyContract: function() {
            wx.openPrivacyContract({
                fail: function() {
                    wx.showToast({
                        title: "遇到错误",
                        icon: "error"
                    });
                }
            });
        },
        exitMiniProgram: function() {
            this.setData({
                showPrivacy: !1,
                showRecommendInstitution: !1
            });
        },
        handleAgreePrivacyAuthorization: function() {
            this.setData({
                showPrivacy: !1
            }), this.init(), this.getLoc();
        },
        imageLoad: function(t) {
            if (0 == this.data.imgwidth || 0 == this.data.imgheight) {
                var i = t.detail.width / t.detail.height, e = Number(this.data.contentMagin.replace("px", "").replace("rpx", "")), a = this.data.screenWidth - 2 * e - 10, n = a / i;
                this.setData({
                    imgwidth: a,
                    imgheight: n
                });
            }
        },
        init: function() {
            var t = this;
            wx.getSystemInfo({
                success: function(i) {
                    t.setData({
                        screenHeight: i.windowHeight,
                        screenWidth: i.windowWidth
                    });
                }
            });
        },
        getLoc: function() {
            var t = this, i = a.getStorageSync(a.storageKey.locationInfo);
            null != i && null != i && "" != i && i.expireTimestamp > new Date().getTime() ? (t.setData({
                latitude: i.latitude,
                longitude: i.longitude
            }), t.selectWcaInstitutionByCityCode()) : wx.getLocation({
                type: "gcj02",
                success: function(i) {
                    console.log("微信获取的位置信息", i);
                    var e = n.qqMapToBMap(i.longitude, i.latitude);
                    t.setData({
                        showRecommendInstitution: !0,
                        latitude: e[1],
                        longitude: e[0]
                    }), a.setStorageSync(a.storageKey.locationInfo, {
                        expireTimestamp: new Date().getTime() + 6e5,
                        latitude: e[1].toString(),
                        longitude: e[0].toString()
                    }), t.selectWcaInstitutionByCityCode();
                },
                fail: function(i) {
                    console.log("微信获取位置信息失败：" + i.errMsg), t.setData({
                        showRecommendInstitution: !1
                    }), i.errMsg.indexOf("频繁") > -1 ? console.log("请勿频繁定位") : wx.showModal({
                        title: "提示",
                        content: "如果您想要显示推荐机构，可点击小程序右上角“···”，设置中允许使用位置信息，并重新进入小程序",
                        showCancel: !1
                    });
                }
            });
        },
        selectWcaInstitutionByCityCode: function() {
            var a = this, n = e.apiRoute.selectWcaInstitutionByCityCode + "?latitude=" + this.data.latitude + "&longitude=" + this.data.longitude;
            i.request(i.HttpMethod.GET, n, {}).then(function(i) {
                if ("20000" == i.code) {
                    a.setData({
                        institution: i.data[0]
                    });
                    var e = [];
                    null != i.data[0].imageList ? i.data[0].imageList.forEach(function(i) {
                        e.push(t.institutionImageUrl + i);
                    }) : e.push(t.defaultInstitutionImageURL), a.setData({
                        background: e
                    });
                } else a.setData({
                    institution: void 0
                });
            });
        },
        redirectToInstitutionDetail: function() {
            wx.navigateTo({
                url: "/pages/institution-detail/institution-detail?institutionId=" + this.data.institution.id
            });
        },
        previewImage: function(t) {
            console.log("show image");
            var i = t.currentTarget.dataset.index, e = this.data.background;
            wx.previewImage({
                current: e[i],
                urls: e
            });
        }
    }
});